<template>
	<view>
		<view class=""
			style="display: flex;flex-direction: row-reverse;align-items: center;margin-right: 20rpx;margin-top: 20rpx;">
			<u-button type="primary" @click="addTime" size="medium">添加</u-button>
		</view>
		<u-picker @confirm="selectConfirm" mode="multiSelector" v-model="show"  :default-selector='[0,0,0,0,0,0,0]' :range="multiSelector"></u-picker>
		<view class="" style="width: 100%;height: 150rpx;padding:0 20rpx;margin-top: 20rpx;" v-for="item in optionTime"
			:key="item.id">
		
			<view class="aaa" @click="openPhone(item.phone)"
				style="width: 100%;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: space-between;border-radius: 20rpx;font-size: 32rpx;">
				
					<view class="" style="width: 80%;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: space-around;">
						<view style="margin-left: 20rpx;">
							开始：{{item.beginTime}}
						</view>
						<view>
							结束：{{item.endTime}}
						</view>
					</view>
				
				<view style="display: flex;flex-direction: row;margin-right: 20rpx;">
					<u-button type="error" @click="deleteWaiter(item.id)" size="mini">删除</u-button>
				</view>
				<u-modal show-cancel-button=true v-model="modalShow" @confirm="okFinsh" content="确认删除？"></u-modal>
				
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				optionTime:[],
				modalShow:false,
				id:'',
				show:false,
				multiSelector:[
					['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'],
					[':'],
					['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59'],
					['——'],
					['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'],
					[':'],
					['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59'],
				]
			}
		},
		onShow(){
			this.getTime()
		},
		methods: {
			getTime() {
				this.$u.get('life/shop/time/page', {}).then(res => {
					console.log("我是营业时间");
					console.log(res)
					this.optionTime = res.list
					console.log('6666699999988888');
					console.log(this.optionTime);
			
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			deleteWaiter(e){
				this.modalShow = true
				this.id = e
			},
			okFinsh(){
				let delArr = []
				delArr.push(this.id)
				this.$u.delete('life/shop/time/delete', delArr).then(res => {
					console.log(res)
					if (res.success) {
						this.$refs.uToast.show({
							title: "删除成功",
							type: 'success',
						})
						this.getTime()
					} else {
						this.$refs.uToast.show({
							title: "删除失败",
							type: 'error',
						})
					}
				
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			addTime(){
				this.show= true
			},
			selectConfirm(e){
				let startTimeHour = this.multiSelector[0][e[0]]
				let startTimeMinute = this.multiSelector[2][e[2]]
				let endTimeHour = this.multiSelector[4][e[4]]
				let endTimeMinute = this.multiSelector[6][e[6]]
				console.log('我是开始时间');
				console.log(startTimeHour + ':' + startTimeMinute);
				console.log("我是结束时间");
				console.log(endTimeHour + ':' + endTimeMinute);
				let startTime = startTimeHour + ':' + startTimeMinute
				let endTime = endTimeHour + ':' + endTimeMinute
				this.$u.post('life/shop/time/save', {beginTime:startTime,endTime:endTime}).then(res => {
					console.log(res)
					if(res.success){
						this.$refs.uToast.show({
							title: "添加成功",
							type: 'success',
						})
						this.getTime()
					}
				
					// this.$refs.uToast.show({
					// 	title: "请求失败",
					// 	type: 'error',
					// })
					
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
				
			}
		}
	}
</script>

<style>
.aaa{
	background-color: #f0f0f0;
}
</style>
